require 'ServerDAO'

class ServerModel
  
  def getNationwideTotals()
    
    inst = ServerDAO.instance()
    names = inst.fetchCandidateNames
    response = []
    response.push(names)
    votes = []
    names.each{|itm|
      votes.push( inst.fetchCandidateVotes(itm) )
    }
    response.push(votes)
    return response
  end

  
  def getCandidateNames()
    inst = ServerDAO.instance()
    return inst.fetchCandidateNames
  end

  def addNewTable(hashp)
    inst = ServerDAO.instance()
    tableKey = hashp["table"]
    tableNum = hashp["tablenum"].to_i
    cd1 = hashp["cd1"]
    cd2 = hashp["cd2"]
    cd3 = hashp["cd3"]
    vt1 = hashp["votes1"].to_i
    vt2 = hashp["votes2"].to_i
    vt3 = hashp["votes3"].to_i
    inst.databaseTableInsert(tableKey,tableNum,cd1,cd2,cd3,vt1,vt2,vt3)
    
  end
  
  def delTable(hashp)
    inst = ServerDAO.instance()
    tableKey = hashp["table"]    
    inst.dbTableDel(tableKey)
  end
  
  def updateTable(hashp)
    inst = ServerDAO.instance()
    tableKey = hashp["table"]
    tableNum = hashp["tablenum"].to_i
    cd1 = hashp["cd1"]
    cd2 = hashp["cd2"]
    cd3 = hashp["cd3"]
    vt1 = hashp["votes1"].to_i
    vt2 = hashp["votes2"].to_i
    vt3 = hashp["votes3"].to_i
    inst.dbtableUpdate(tableKey,tableNum,cd1,cd2,cd3,vt1,vt2,vt3)
    
  end
  
  
end